package com.zhaojiadi.thinking.in.spring.ioc.overview.dependency.injection;

import com.zhaojiadi.thinking.in.spring.ioc.overview.domain.User;
import com.zhaojiadi.thinking.in.spring.ioc.overview.repository.UserRepository;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;

import java.util.Map;

/**
 * @Description:
 */
public class DependencyInjectionDemo {

    public static void main(String[] args) {
        //配置xml配置文件
        //启动spring上下文
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/META-INF/dependency-injection-context.xml");

        //依赖来源一:自定义Bean
        UserRepository userRepository = applicationContext.getBean("userRepository", UserRepository.class);
        System.out.println(userRepository);

        //依赖来源二:依赖注入(内建依赖)
        System.out.println(userRepository.getBeanFactory());
        ObjectFactory<ApplicationContext> userFactory = userRepository.getObjectFactory();
        System.out.println(userFactory.getObject()==applicationContext);

        //依赖来源三:容器内建Bean
        Environment environment = applicationContext.getBean(Environment.class);
        System.out.println("获取Environment类型的Bean:"+environment);

        //

    }


}
